trigger inactive_HCP_delete_callplan on HCP__c (after update) {
    
    list<id> hcpid=new list<id>();
    for(HCP__c h:trigger.new){
        if(trigger.oldmap.get(h.id).active__c ==true && h.active__c==false ){
            hcpid.add(h.id);
        }
    }
    
    if(hcpid.size()>0){
        list<callplan__c> cpl=[select id from callplan__c where HCP__c in:hcpid and CallPlanDate__c >=:date.today() ];
        if(cpl.size()>0){
            for(callplan__c cp:cpl){
                cp.delete_mark__c=true;
            }
            update cpl;
            delete cpl;
        }
    }

}